/*
 * Factory.java
 *
 * Created on November 25, 2007, 2:19 PM
 *
 * Copyright (C) 2007-2008  Hylke van der Schaaf
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, in version 3 of the License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */
package hextd.creep;

import hextd.core.Context;
import java.util.HashMap;
import java.util.Map;

/**
 *
 * @author hylke
 */
public class Factory {

	public static enum Enemy {

		BlueBox(CreepBlueBox.type, new CreepBlueBox()),
		FastForward(CreepFastForward.type, new CreepFastForward()),
		GreenPlus(CreepGreenPlus.type, new CreepGreenPlus()),
		HardGrey(CreepHardGrey.type, new CreepHardGrey()),
		HealthyHelix(CreepHealthyHelix.type, new CreepHealthyHelix()),
		PeachyPinata(CreepPeachyPinata.type, new CreepPeachyPinata()),
		ProtectedPink(CreepProtectedPink.type, new CreepProtectedPink()),
		RedRaver(CreepRedRaver.type, new CreepRedRaver()),
		SprintingSalmon(CreepSprintingSalmon.type, new CreepSprintingSalmon()),
		YellorRotor(CreepYellowRotor.type, new CreepYellowRotor());
		private final String name;
		private final Creep instance;

		Enemy(String name, Creep instance) {
			this.name = name;
			this.instance = instance;
		}

		public String getName() {
			return this.name;
		}

		public float getPreferredDelay() {
			return this.instance.getPreferredDelay();
		}

		public Creep getCopy(Context context, int owner, int path, float delay, long health, int price, int score, Creep.Size s) {
			return instance.create(context, owner, path, delay, health, price, score, s);
		}
	}
	private static Map<String, Enemy> table = new HashMap<String, Enemy>();

	static {
		for (Enemy enemy : Enemy.values()) {
			table.put(enemy.getName(), enemy);
		}
		table.put("gg", Enemy.GreenPlus);
	}

	public static boolean isEnemy(String name) {
		return table.containsKey(getNamePart(name));
	}

	public static Enemy identifyEnemy(String name) {
		return table.get(getNamePart(name));
	}

	public static Creep getEnemy(String name, Context context, int owner, int path, float delay, long health, int price, int score) {
		return table.get(getNamePart(name)).getCopy(context, owner, path, delay, health, price, score, getSize(name));
	}

	public static String getNamePart(String name) {
		switch (name.charAt(0)) {
			case 'L':
			case 'S':
			case 'N':
				return name.substring(1);
			default:
				return name;
		}
	}

	public static Creep.Size getSize(String name) {
		switch (name.charAt(0)) {
			case 'L':
				return Creep.Size.large;
			case 'S':
				return Creep.Size.small;
			case 'N':
			default:
				return Creep.Size.normal;
		}
	}
}
